<?
	include("includes/config.php");
	include("includes/login.php");
	include("includes/functions.php");
?>
<html>
	<head>
		<link rel="stylesheet" type="text/css" href="css/style.css" />
	</head>
	<body>
		<div id="header"><h1> <? echo detaliFirma('nume_firma'); ?></h1></div>
		<div id="warper">
			<?
				$resMeniu = mysql_query("select * from meniu");
			?>
			<div id="menu">
				<ul>
					<? while($rowMen = mysql_fetch_array($resMeniu)): ?>
					<li><a href="<?echo $rowMen['link'];?>"><? echo $rowMen['numeLink']; ?></a></li>
					<? endwhile; ?>
				</ul>
			</div>
			<div id="content">
				<div id="contentWrap">
					<div class="block">
						<div id="cautaPartener">
							<form action="" method="post">
							<label>Cauta Partener</label>
									<input class="text" type="text" name="cauta"  />
									<input class="buton" type="submit" value="Cauta Partener" name="cautaPartener" />
							</form>
						</div>
							<div id="partenerNou">
								<p>
									<a href="/partener_nou.php" class="buton" > Partener Nou </a>
								</p>
								
							</div>
					<div style="clear:both;"></div>
					</div>
					
					<div id="rezultateParteneri">
						<table>
							<tr id="capTabel">
								<td style="width:330px;">Nume Partener</td>
								<td style="width:170px;">Numar Inmatriculare</td>
								<td >Detalii</td>
							</tr>
							<?
								if(@$_POST['cautaPartener']){
									 $cauta = $_POST['cauta'];
									 $nrmatnospace  =str_replace(" ","",$cauta);
									 if(preg_match('/(\w\d{1,3}\w{3})/',$nrmatnospace)){
										$nrmat = preg_replace('/(\w)(\d{1,3})(\w{3})/', "$1-$2-$3",$nrmatnospace);
										$nrmat = strtoupper($nrmat);
										$queryfrom = "parteneri.nume,parteneri.id_client,parteneri_masini.numar_inmatriculare from parteneri_masini,parteneri where numar_inmatriculare = '".$nrmat." ' and parteneri.id_client = parteneri_masini.id_partener ";
									}else{
										$queryfrom = "id_client, nume from parteneri where nume like  '%$cauta%'";
									}
									$rescauta = mysql_query("select ".$queryfrom."") or die(mysql_error());
									while($rowCauta = mysql_fetch_array($rescauta)):
							?>
							
							<tr>
								<form action="detaliimasina.php" method="get">
									<td><? echo $rowCauta['nume'] ; ?></td>
										<td>
											<input type="hidden" name="id_partener" value="<? echo $rowCauta['id_client'] ; ?>">
											<select class="tableSelect" name="masina" style="width:170px;">
												<?
													$id_client = $rowCauta['id_client'];
													$resNrMatriculare = mysql_query("select * from parteneri_masini where id_partener =  '$id_client' ");
													while($rowMat = mysql_fetch_array($resNrMatriculare)):
												?>
													<option value="<?echo $rowMat['id_masina']; ?>"><? echo $rowMat['numar_inmatriculare'];?></option>
												<? endwhile; ?>
											</select>
											
										</td>
									<td align="center">
										<input  class="buton" type="submit" name="detaliimasina" value="Detalii Masina">&nbsp;
										
									</td>
								</form>
							</tr>
							<? endwhile; }	?>
							
						</table>
					</div>
					
					
				</div>
		</div>
	</body>
</html>